package com.cisetech.web.bobocai.houtai;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cisetech.vo.Page;
import com.cisetech.vo.bobocai.CodeVo;
import com.cisetech.vo.bobocai.LRegion;
import com.cisetech.service.RegionService;

/**
 * 后台添加code控制器
 * @author Administrator
 *
 */
@Controller
@RequestMapping(value="/ht/region")
public class RegionController {
	@Autowired
	RegionService regionService;
	
	@RequestMapping(value="/region",method=RequestMethod.GET)
	public String region(Model model,HttpServletRequest request,HttpServletResponse response){
		
		return "houtai/addregion";
	}
	@ResponseBody
	@RequestMapping(value="/addregion",method=RequestMethod.POST)
	public String addregion(LRegion region,HttpServletRequest request,HttpServletResponse response){
		int i = regionService.addregion(region);
		if(i==1){
			return "0";	
		}else{
			return "1";
		}
	}
	
	
	@RequestMapping(value="/regionlist",method=RequestMethod.GET)
	public String regionlist(Model model,HttpServletRequest request,HttpServletResponse response){
		
		return "houtai/regionlist";
	}
	@ResponseBody
	@RequestMapping(value="/getList",method=RequestMethod.POST)
	public Page<LRegion> regionlists(LRegion region,HttpServletRequest request,HttpServletResponse response){
		if (region.getcCity()!=null && !"".equals(region.getcCity()) && (region.geteCity()==null || "".equals(region.geteCity()))){
			region.seteCity(region.getcCity());
		}
		return regionService.getList(region);
	}
	
	@ResponseBody
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	public String deleteLRegion(LRegion region,HttpServletRequest request,HttpServletResponse response){
		int i = regionService.deleteLRegion(region.getId()+"");
			return i+"";
	}
	@ResponseBody
	@RequestMapping(value="/getlists",method=RequestMethod.POST)
	public List<LRegion> getlistss(LRegion region,HttpServletRequest request, HttpServletResponse response){
		
		List<LRegion> list = regionService.getlistss(region);
		return list;
	}
	@ResponseBody
	@RequestMapping(value="/updateredian",method=RequestMethod.POST)
	public String updateredian(LRegion region,HttpServletRequest request, HttpServletResponse response){
		try {
			if (region!=null){
				if (region.getRedian()!=null && !"".equals(region.getRedian()) && "1".equals(region.getRedian())){
					region.setRedian("0");
				}else{
					region.setRedian("1");
				}
				int i = regionService.updateByPrimaryKeySelective(region);
				return i + "";
			}
		} catch (Exception e) {
			return "10";
		}
		return "10";
	}
	
}
